package ypt.fqh.maptest1.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.tencent.lbssearch.object.result.SearchResultObject;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;

import java.util.List;

import ypt.fqh.maptest1.R;

public class SearchResultsAdapter extends RecyclerView.Adapter<SearchResultsAdapter.SearchPoiItemViewHolder>{

    private List<SearchResultObject.SearchResultData> mPoiInfos;

    public SearchResultsAdapter(List<SearchResultObject.SearchResultData> mPoiInfos) {
        this.mPoiInfos = mPoiInfos;
    }

    @NonNull
    @Override
    public SearchResultsAdapter.SearchPoiItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = null;
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
        SearchPoiItemViewHolder viewHolder = new SearchPoiItemViewHolder(view);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int position = viewHolder.getAdapterPosition();
                String title = mPoiInfos.get(position).title;
                String address = mPoiInfos.get(position).address;
                LatLng latLng = mPoiInfos.get(position).latLng;
                double distance = mPoiInfos.get(position).distance;

                System.out.println("title:"+title);
                System.out.println("address:"+address);
                System.out.println("distance:"+distance);
                System.out.println("latLng:"+latLng.getLatitude()+"======="+latLng.getLongitude());
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull SearchResultsAdapter.SearchPoiItemViewHolder holder, int position) {
        holder.mTitle.setText(mPoiInfos.get(position).title);
    }

    @Override
    public int getItemCount() {
        return mPoiInfos.size();
    }

    public static class SearchPoiItemViewHolder extends RecyclerView.ViewHolder {
        private TextView mTitle;
        public SearchPoiItemViewHolder(@NonNull View itemView) {
            super(itemView);
            mTitle = itemView.findViewById(R.id.expandabledListItem);
        }
    }
}
